package org.xdq.demo.service.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;
import org.xdq.demo.dao.EmployeeDao;
import org.xdq.demo.dto.EmployeeDto;
import org.xdq.demo.model.Employee;
import org.xdq.demo.service.EmployeeService;
import org.xdq.demo.util.MyBatisUtils;

import java.util.List;

@Service //作用：说明这是一个业务对象，并放入Spring容器中，与@Component类似
public class EmployeeServiceImpl implements EmployeeService {
    @Override
    public List<Employee> getEmployeeList(EmployeeDto dto) {

        SqlSession session = MyBatisUtils.openSession();

        try{
            EmployeeDao employeeDao = session.getMapper(EmployeeDao.class);
            List<Employee> list = employeeDao.findEmpoyeeList(dto);
            session.commit();
            return list;
        }catch(Exception e){
            session.rollback();
            throw new RuntimeException(e);
        }finally{
            session.close();
        }


    }
}
